Skip to content

[host]: SystemTagCreator ignoreIfExisting to prevent duplicate tags#3950

Open
MatheMatrix wants to merge 2 commits into
5.5.22from
sync/songtao.liu/fix/ZSTAC-58237-v2
Open

[host]: SystemTagCreator ignoreIfExisting to prevent duplicate tags#3950
MatheMatrix wants to merge 2 commits into
5.5.22from
sync/songtao.liu/fix/ZSTAC-58237-v2

Conversation

@MatheMatrix
Copy link
Copy Markdown
Owner

Resolves: ZSTAC-58237

sync from gitlab !9841

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 13, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: http://open.zstack.ai:20001/code-reviews/zstack-cloud.yaml (via .coderabbit.yaml)

Review profile: CHILL

Plan: Pro

Run ID: ad5c7c5f-ac95-4583-9fff-be13c6e9e091

📥 Commits

Reviewing files that changed from the base of the PR and between 92bd989 and e17a62e.

⛔ Files ignored due to path filters (1)
  • conf/errorElaborations/Elaboration.json is excluded by !**/*.json
📒 Files selected for processing (1)
  • compute/src/main/java/org/zstack/compute/host/HostBase.java
🚧 Files skipped from review as they are similar to previous changes (1)
  • compute/src/main/java/org/zstack/compute/host/HostBase.java

Walkthrough

该 PR 在 HostBase.updateHostConnectedTime 中将创建 HostSystemTags.HOST_CONNECTED_TIME 的 SystemTagCreator 配置为 ignoreIfExisting = true,避免在标签已存在时创建失败。

Changes

Host System Tag Configuration

Layer / File(s) Summary
Host Connected Time Tag Creation
compute/src/main/java/org/zstack/compute/host/HostBase.java
updateHostConnectedTime 方法中的 SystemTagCreator 配置添加 ignoreIfExisting = true 标志,允许在 HostSystemTags.HOST_CONNECTED_TIME 标签已存在时安全跳过创建。

Estimated Code Review Effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Poem

🐰 一行代码轻轻改,
主机标签不再抛错,
若已存在则默默越过,
连接时间静好如初,
小改动,大安心。

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The pull request title follows the required [scope]: format with '[host]' as scope and is 67 characters, within the 72-character limit.
Description check ✅ Passed The pull request description is related to the changeset, mentioning the JIRA issue ZSTAC-58237 and referencing the gitlab sync, which aligns with the SystemTagCreator change.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch sync/songtao.liu/fix/ZSTAC-58237-v2

Comment @coderabbitai help to get the list of available commands and usage tips.

@zstack-robot-1
Copy link
Copy Markdown
Collaborator

Comment from yaohua.wu:

Review: MR !9841 — ZSTAC-58237

总结

本次修复针对重连物理机时 HOST_CONNECTED_TIME system tag 被反复删除再创建(即使值未变化)导致 mysql-bin 快速增长的问题。修改点为在 HostBase.updateHostConnectedTimeSystemTagCreator 上设置 ignoreIfExisting = true,当同一 tag(UUID 由 resourceUuid + resourceType + tag 内容确定性生成)已存在时直接跳过写入,避免不必要的 DB 操作。

SystemTag.doCreate() 实现来看,ignoreIfExisting = true 会在两处截断:①先查 count 发现 uuid 已存在则返回 null;② persist 时捕获 Duplicate entry 异常静默返回 null。结合调用侧已有的前置守卫 if (hostStatus == HostStatus.Connected && !tagExists) 可知,正常路径下该 tag 不存在时才会走到 creator;ignoreIfExisting 起到并发竞态下的兜底保护作用,设计合理。

recreate = false 已经确保不会先删再建;connectedTimeSystem.currentTimeMillis(),每次重连值不同,因此此处 ignoreIfExisting 的语义是"同一主机本次连接时间 tag 已写入则跳过",符合幂等预期。

Jira 中原始 issue 描述的是 iommuStatus tag 在 premium 模块(已由 MR !7980 修复),本 MR 修复的是同类问题在 HOST_CONNECTED_TIME tag 上的对应分支(5.5.22 版本),修复逻辑一致、覆盖完整。

无阻塞性问题,建议合并。

Verdict: APPROVED


🤖 Robot Reviewer

zstack added 2 commits May 19, 2026 01:02
…ut values

Match \d+ seconds instead of hardcoded 5, so it works with the new 30s timeout.

Resolves: ZSTAC-77160
@MatheMatrix MatheMatrix force-pushed the sync/songtao.liu/fix/ZSTAC-58237-v2 branch from 92bd989 to e17a62e Compare May 19, 2026 08:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants